from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import app.helpers.views
import app.views

######### URL MAPPING #########

# When mapping URLs to to RequestHandlers, we use a CamelCase convention,
# minus there are some exceptions. See helpers.views.discover for details

# Connect any URLs that don't follow the CamelCase convention
import app.views.root
url_mapping = [
  ('/', app.views.root.Index),
]

# Use discovery on the rest
for name in dir(app.views):
  if name.startswith('_'):
    continue
  try:
    url_mapping += app.helpers.views.discover(
      getattr(__import__('app.views.%s' % name).views, name))
  except ImportError:
    pass

######### ACTUAL APP SETUP ######### 

application = webapp.WSGIApplication(url_mapping, debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
